package com.woniu.cms.psm.core.controller;


import com.woniu.cms.psm.core.entity.PmPractical;
import com.woniu.cms.psm.core.service.IPmPracticalService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lilili
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/pm-practical")
@Api(tags = "项目实际工作量控制器")
public class PmPracticalController {
    @Resource
    private IPmPracticalService practicalService;

    @ApiOperation("添加实际工作量")
    @PostMapping("/add")
    public Result<Object> add(@RequestBody PmPractical practical){
        practical.setId(null);
        boolean save = practicalService.save(practical);
        if(!save){
            return Result.error(save);
        }
        return Result.common(save);
    }


    /**
     * 删除和修改只有系统管理员可以
     */



    @ApiOperation("修改实际工作量")
    @PutMapping("/update")
    public Result<Object> update(@RequestBody PmPractical practical){
        boolean update = practicalService.updateById(practical);
        if(!update){
            return Result.error(update);
        }
        return Result.common(update);
    }

    @ApiOperation("批量删除实际工作量")
    @DeleteMapping("/delete")
    public Result<Object> delete(@RequestBody Integer[] ids){
        boolean delete = practicalService.removeBatchByIds(Arrays.asList(ids));
        if(!delete){
            return Result.error(delete);
        }
        return Result.common(delete);
    }

    @ApiOperation("展示实际工作量")
    @GetMapping("/all")
    public Result<List<PmPractical>> all(){
        List<PmPractical> list = practicalService.list();
        return Result.common(list);
    }
}

